import json
from pyecharts.charts import Map
from pyecharts.options import VisualMapOpts, TitleOpts

f = open("/Users/study/python/疫情.txt", "r", encoding="utf-8")
data = f.read()
f.close()

data_dict = json.loads(data)
sf = data_dict["areaTree"][0]["children"]

sf_list = []
for child in sf:
    sf_name = child["name"]
    sf_data = child["total"]["confirm"]
    sf_tuple = (sf_name, sf_data)
    sf_list.append(sf_tuple)

map1 = Map()

map1.add("中国地图", sf_list, "china")

map1.set_global_opts(
    title_opts=TitleOpts(title="全国疫情地图", pos_left="center", pos_bottom="1%"),
    visualmap_opts=VisualMapOpts(
        is_show=True,
        is_piecewise=True,
        pieces=[
            {"min": 1, "max": 99, "label": "1-99", "color": "#CCFFFF"},
            {"min": 100, "max": 999, "label": "100-999", "color": "#FFFF99"},
            {"min": 1000, "max": 4999, "label": "1000-4999", "color": "#FF9966"},
            {"min": 5000, "max": 9999, "label": "5000-9999", "color": "#FF6666"},
            {"min": 10000, "max": 99999, "label": "10000-99999", "color": "#CC3333"},
            {"min": 100000, "label": "100000+", "color": "#990033"}
        ]
    )
)

map1.render("全国疫情地图.html")




